home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C23 / Nonlocal.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  750 b   |  36 lines

  1. //: C23:Nonlocal.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // setjmp() & longjmp()
  7. #include <iostream>
  8. #include <csetjmp>
  9. using namespace std;
  10.  
  11. class Rainbow {
  12. public:
  13.   Rainbow() { cout << "Rainbow()" << endl; }
  14.   ~Rainbow() { cout << "~Rainbow()" << endl; }
  15. };
  16.  
  17. jmp_buf kansas;
  18.  
  19. void oz() {
  20.   Rainbow rb;
  21.   for(int i = 0; i < 3; i++)
  22.     cout << "there's no place like home\n";
  23.   longjmp(kansas, 47);
  24. }
  25.  
  26. int main() {
  27.   if(setjmp(kansas) == 0) {
  28.     cout << "tornado, witch, munchkins...\n";
  29.     oz();
  30.   } else {
  31.     cout << "Auntie Em! "
  32.          << "I had the strangest dream..."
  33.          << endl;
  34.   }
  35. } ///:~
  36.